package singleton.doublelocked;

/**
 * 双锁/双重校验方式
 * 线程安全
 */
public class Singleton {
    private Singleton(){}
    private volatile static Singleton instance;

    public static synchronized Singleton getInstance(){
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

    public void show(){
        System.out.println("this is instance");
    }
}
